package com.suda.sudaexamsystem.service.impl;

import com.suda.sudaexamsystem.mapper.ExamPaperMapper;
import com.suda.sudaexamsystem.mapper.QuestionMapper;
import com.suda.sudaexamsystem.pojo.ExamPaper;
import com.suda.sudaexamsystem.service.ExamPaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class ExamPaperSeviceImpl implements ExamPaperService {
    @Autowired
    private ExamPaperMapper examPaperMapper;
    @Autowired
    private QuestionMapper questionMapper;

    @Override
    @Transactional
    public void addExamPaper(ExamPaper examPaper) {
        examPaperMapper.addExamPaper(examPaper);
        // 添加试卷中的题目
        questionMapper.addQuestionBatch(examPaper.getQuestionList());
    }

    @Override
    @Transactional
    public void updateExamPaper(ExamPaper examPaper) {
        examPaperMapper.updateExamPaper(examPaper);
    }

    @Override
    @Transactional
    public void deleteById(int examId) {
        // 删除题目
        questionMapper.deleteByExamId(examId);
        examPaperMapper.deleteById(examId);
    }

    @Override
    @Transactional
    public ExamPaper findById(int examId) {
        return examPaperMapper.findById(examId);
    }

    @Override
    @Transactional
    public List<ExamPaper> findByClazzId(int clazzId) {
        return examPaperMapper.findByClazzId(clazzId);
    }
}
